<template>
	<div class="voice-way-wrapper">
		<el-row>
			<el-col :span="4">
				<div class="grid-content bg-purple">语音拟合方式</div>
			</el-col>
			<el-col :span="20">
				<div v-if="videoType === 'real-time-fitting'"> 视频原声 </div>
				<div v-if="videoType === 'video-switching' || videoType === 'no-video'">TTS</div>
				<div v-if="videoType === 'pre-recorded-video'">
					<el-radio-group v-model="voiceWay" @change="changeVoiceWay">
						<el-radio label="video-native">视频原声</el-radio>
						<el-radio label="tts">TTS</el-radio>
					</el-radio-group>
				</div>
			</el-col>
		</el-row>
	</div>
</template>

<script>
import AIWorkflow from '@/modules/workFlow.js';
export default {
	props: {
		videoType: {
			type: String,
			default: () => ''
		},

		showDetail: {
			type: Boolean,
			default: () => false
		}
	},
	computed: {
		AIWorkflow
	},

	watch: {
		videoType: {
			handler(newval,oldVal) {
				console.log('@@@ai videoType',newval,oldVal);
				if (newval === 'pre-recorded-video' && AIWorkflow.getRobotProperty() && !AIWorkflow.getRobotProperty().audioType){
					this.voiceWay = 'video-native'; // 默认视频原声
				} else if (newval === 'pre-recorded-video' && oldVal !== 'pre-recorded-video'){
					if ( AIWorkflow.getRobotProperty() && AIWorkflow.getRobotProperty().audioType && AIWorkflow.getRobotProperty().videoType === 'pre-recorded-video'){
						this.voiceWay = AIWorkflow.getRobotProperty().audioType;
					} else {
						this.voiceWay = 'video-native'; // 默认视频原声
					}
				} else if (newval === 'pre-recorded-video' && AIWorkflow.getRobotProperty() && AIWorkflow.getRobotProperty().audioType && AIWorkflow.getRobotProperty().videoType === 'pre-recorded-video'){
					this.voiceWay = AIWorkflow.getRobotProperty() && AIWorkflow.getRobotProperty().audioType ? AIWorkflow.getRobotProperty().audioType : 'video-native';
				}
			},
			immediate:true
		}
	},
	data() {
		return {
			voiceWay: 'video-native'
		};
	},
	mounted(){
		console.log('###voiceWay AIWorkflow getRobotProperty',this.videoType,AIWorkflow.getRobotProperty(),AIWorkflow.getRobotProperty().audioType);
		this.voiceWay = AIWorkflow.getRobotProperty() && AIWorkflow.getRobotProperty().audioType ? AIWorkflow.getRobotProperty().audioType : 'video-native';
	},
	methods: {
		// 切换语音拟合方式
		changeVoiceWay(val) {
			if (this.videoType === 'pre-recorded-video') {
				// 弹框确定清空ai话术模版。
				// this.$emit('updateAudioType',val);
				AIWorkflow.setRobotProperty({ audioType: val });
			}
		},
		resetVoiceWay(audioType){
			if (audioType === 'tts'){
				this.voiceWay = 'video-native';
			} else {
				this.voiceWay = 'tts';
			}
		}
	}
};
</script>
<style lang="less" scoped>
.el-col {
	padding: 10px 0;
}
</style>
